Sensor Fusion for Kinetis MCUs (ISSDK/KSDK version)
driver_FXOS8700.c File Reference
+ Include dependency graph for driver_FXOS8700.c:

Go to the source code of this file.

Macros

#define FXOS8700_ACCEL_FIFO_SIZE   32
 
#define FXOS8700_MAG_FIFO_SIZE   1
 
#define FXOS8700_COUNTSPERG   8192.0
 
#define FXOS8700_COUNTSPERUT   10
 

Functions

int8_t FXOS8700_Init (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXOS8700_ReadMagData (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXOS8700_Read (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 
int8_t FXOS8700_Idle (PhysicalSensor *sensor, SensorFusionGlobals *sfg)
 

Variables

const registerreadlist_t FXOS8700_WHO_AM_I_READ []
 
const registerreadlist_t FXOS8700_F_STATUS_READ []
 
registerreadlist_t FXOS8700_DATA_READ []
 
const registerwritelist_t FXOS8700_Initialization []
 
const registerwritelist_t FXOS8700_FULL_IDLE []
 

Macro Definition Documentation

#define FXOS8700_ACCEL_FIFO_SIZE   32

FXOS8700 (accel), MMA8652, FXLS8952 all have 32 element FIFO.

Definition at line 42 of file driver_FXOS8700.c.

Referenced by FXOS8700_Init().

#define FXOS8700_COUNTSPERG   8192.0

Definition at line 144 of file driver_FXOS8700.c.

Referenced by FXOS8700_Init().

#define FXOS8700_COUNTSPERUT   10

Definition at line 145 of file driver_FXOS8700.c.

Referenced by FXOS8700_Init().

#define FXOS8700_MAG_FIFO_SIZE   1

FXOS8700 (mag), MAG3110 have no FIFO so equivalent to 1 element FIFO.

Definition at line 43 of file driver_FXOS8700.c.

Function Documentation

int8_t FXOS8700_Idle ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 296 of file driver_FXOS8700.c.

297 {
298  int32_t status;
299  if(sensor->isInitialized == (F_USING_ACCEL|F_USING_MAG)) {
300  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, FXOS8700_FULL_IDLE );
301  sensor->isInitialized = 0;
302 #if F_USING_ACCEL
303  sfg->Accel.isEnabled = false;
304 #endif
305 #if F_USING_MAG
306  sfg->Mag.isEnabled = false;
307 #endif
308  } else {
309  return SENSOR_ERROR_INIT;
310  }
311  return status;
312 }
const registerwritelist_t FXOS8700_FULL_IDLE[]
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
MagSensor Mag
magnetometer storage
bool isEnabled
true if the device is sampling
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38
int8_t FXOS8700_Init ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 151 of file driver_FXOS8700.c.

Referenced by main().

152 {
153  int32_t status;
154  uint8_t reg;
155  status = Register_I2C_Read(sensor->bus_driver, sensor->addr, FXOS8700_WHO_AM_I, 1, &reg);
156 
157  if (status==SENSOR_ERROR_NONE) {
158 #if F_USING_ACCEL
159  sfg->Accel.iWhoAmI = reg;
160  sfg->Accel.iCountsPerg = FXOS8700_COUNTSPERG;
161  sfg->Accel.fgPerCount = 1.0F / FXOS8700_COUNTSPERG;
162 #endif
163 #if F_USING_MAG
164  sfg->Mag.iWhoAmI = reg;
166  sfg->Mag.fCountsPeruT = (float) FXOS8700_COUNTSPERUT;
167  sfg->Mag.fuTPerCount = 1.0F / FXOS8700_COUNTSPERUT;
168 #endif
169  if (reg != FXOS8700_WHO_AM_I_PROD_VALUE) {
170  return SENSOR_ERROR_INIT; // The whoAmI did not match
171  }
172  } else {
173  // whoAmI will rettain default value of zero
174  // return with error
175  return status;
176  }
177 
178  // Configure and start the fxos8700 sensor. This does multiple register writes
179  // (see FXOS8700_Initialization definition above)
180  status = Sensor_I2C_Write(sensor->bus_driver, sensor->addr, FXOS8700_Initialization );
182 #if F_USING_ACCEL
183  sfg->Accel.isEnabled = true;
184 #endif
185 #if F_USING_MAG
186  sfg->Mag.isEnabled = true;
187 #endif
188 
189  return (status);
190 }
#define FXOS8700_COUNTSPERUT
#define FXOS8700_COUNTSPERG
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
int16_t iCountsPeruT
counts per uT
MagSensor Mag
magnetometer storage
float fuTPerCount
uT per count
bool isEnabled
true if the device is sampling
const registerwritelist_t FXOS8700_Initialization[]
float fCountsPeruT
counts per uT
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
uint8_t iWhoAmI
sensor whoami
#define F_USING_ACCEL
nominally 0x0001 if an accelerometer is to be used, 0x0000 otherwise
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t FXOS8700_Read ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 265 of file driver_FXOS8700.c.

Referenced by main().

266 {
267  int8_t sts1 = 0;
268  int8_t sts2 = 0;
269 #if F_USING_ACCEL
270  sts1 = FXOS8700_ReadAccData(sensor, sfg);
271 #endif
272 
273 #if F_USING_MAG
274  sts2 = FXOS8700_ReadMagData(sensor, sfg);
275 #endif
276 
277  if (sts1)
278  return (sts1);
279  else
280  return (sts2);
281 }
int8_t FXOS8700_ReadMagData(PhysicalSensor *sensor, SensorFusionGlobals *sfg)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int8_t FXOS8700_ReadMagData ( PhysicalSensor sensor,
SensorFusionGlobals sfg 
)

Definition at line 236 of file driver_FXOS8700.c.

Referenced by FXOS8700_Read().

237 {
238  uint8_t I2C_Buffer[6]; // I2C read buffer
239  int32_t status; // I2C transaction status
240  int16_t sample[3];
241 
242  if(!(sensor->isInitialized & F_USING_MAG))
243  {
244  return SENSOR_ERROR_INIT;
245  }
246 
247  // read the six sequential magnetometer output bytes
248  FXOS8700_DATA_READ[0].readFrom = FXOS8700_M_OUT_X_MSB;
249  FXOS8700_DATA_READ[0].numBytes = 6;
250  status = Sensor_I2C_Read(sensor->bus_driver, sensor->addr, FXOS8700_DATA_READ, I2C_Buffer );
251  if (status==SENSOR_ERROR_NONE) {
252  // place the 6 bytes read into the magnetometer structure
253  sample[CHX] = (I2C_Buffer[0] << 8) | I2C_Buffer[1];
254  sample[CHY] = (I2C_Buffer[2] << 8) | I2C_Buffer[3];
255  sample[CHZ] = (I2C_Buffer[4] << 8) | I2C_Buffer[5];
256  conditionSample(sample); // truncate negative values to -32767
257  addToFifo((FifoSensor*) &(sfg->Mag), MAG_FIFO_SIZE, sample);
258  }
259  return status;
260 }
#define CHY
Used to access Y-channel entries in various data data structures.
Definition: sensor_fusion.h:77
void addToFifo(FifoSensor *sensor, uint16_t maxFifoSize, int16_t sample[3])
addToFifo is called from within sensor driver read functions
void * bus_driver
should be of type (ARM_DRIVER_I2C* for I2C-based sensors, ARM_DRIVER_SPI* for SPI) ...
#define MAG_FIFO_SIZE
FXOS8700 (mag), MAG3110 have no FIFO so equivalent to 1 element FIFO.
MagSensor Mag
magnetometer storage
The FifoSensor union allows us to use common pointers for Accel, Mag & Gyro logical sensor structures...
#define CHZ
#define CHX
Used to access X-channel entries in various data data structures.
Definition: sensor_fusion.h:76
void conditionSample(int16_t sample[3])
conditionSample ensures that we never encounter the maximum negative two&#39;s complement value for a 16-...
uint16_t isInitialized
Bitfields to indicate sensor is active (use SensorBitFields from build.h)
uint16_t addr
I2C address if applicable.
#define F_USING_MAG
Definition: magnetic.h:38
registerreadlist_t FXOS8700_DATA_READ[]

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Variable Documentation

registerreadlist_t FXOS8700_DATA_READ[]
Initial value:
=
{
{ .readFrom = FXOS8700_OUT_X_MSB, .numBytes = 6 }, __END_READ_DATA__
}

Definition at line 58 of file driver_FXOS8700.c.

Referenced by FXOS8700_Init(), and FXOS8700_ReadMagData().

const registerreadlist_t FXOS8700_F_STATUS_READ[]
Initial value:
=
{
{ .readFrom = FXOS8700_STATUS, .numBytes = 1 }, __END_READ_DATA__
}

Definition at line 52 of file driver_FXOS8700.c.

Referenced by FXOS8700_Init().

const registerwritelist_t FXOS8700_FULL_IDLE[]
Initial value:
=
{
{ FXOS8700_CTRL_REG1, 0x00, 0x01 },
__END_WRITE_DATA__
}

Definition at line 284 of file driver_FXOS8700.c.

Referenced by FXOS8700_Idle().

const registerwritelist_t FXOS8700_Initialization[]

Definition at line 64 of file driver_FXOS8700.c.

Referenced by FXOS8700_Init().

const registerreadlist_t FXOS8700_WHO_AM_I_READ[]
Initial value:
=
{
{ .readFrom = FXOS8700_WHO_AM_I, .numBytes = 1 }, __END_READ_DATA__
}

Definition at line 46 of file driver_FXOS8700.c.